package com.assessment.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.assessment.entity.Eliminate;
import com.assessment.entity.Staff;
import com.assessment.service.EliminateService;
import com.assessment.service.StaffService;
import com.fasterxml.jackson.databind.util.JSONPObject;

@Controller
@RequestMapping("/eliminate")
public class EliminateController {
	
	@Resource
	private EliminateService eliminateService;
	
	@Resource
	private StaffService staffService;

	@RequestMapping("/selEliminate.do")
	public String getEliminate(Model model,Eliminate eliminate){
		List<Eliminate> eliminate1=(List<Eliminate>)this.eliminateService.selEliminate();
		model.addAttribute("eliminate", eliminate1);
		return "eliminate/eliminate";
		
	}
	
	//���޸�ҳ��
	@RequestMapping(value="/upd.do",produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String updNews(Model model,HttpServletRequest request){
		int id=Integer.parseInt(request.getParameter("staff_id"));
		model.addAttribute("es", this.eliminateService.sel(id));	
		JSONObject object=JSONObject.fromObject(this.eliminateService.sel(id));
		return object.toString();
	}
	
	//�޸���̭��Ա��Ϣ
	@RequestMapping("/updEliminate.do")
	public String updEliminate(Eliminate eliminate,Model model,@RequestParam("staff_id")Integer staff_id){
		System.out.println(staff_id);
		//int id=Integer.parseInt(staff_id);
		System.out.println(staff_id+"+++++++++++++++++");
		eliminate.setStaffId(staff_id);
		this.eliminateService.updEliminate(eliminate);
		model.addAttribute("es", this.eliminateService.sel(staff_id));
		return "redirect:/eliminate/selEliminate.do";
	}
	
	//��������̭��Ա��Ϣҳ��
	@RequestMapping("/add.do")
	public String add(Eliminate eliminate){
		return "eliminate/addEliminate";
	}
	//������̭��Ա
	@RequestMapping("/addEliminate.do")
	public String addEliminate(Eliminate eliminate){
		this.eliminateService.addEliminate(eliminate);
		this.staffService.updState(eliminate.getStaffId());
		return "redirect:/eliminate/selEliminate.do";
	}
//	
//	//�޸�Ա������̭״̬
//	@RequestMapping("/staffState.do")
//	public String updStaffState(Integer staffId ,Eliminate eliminate){
//		System.out.println(eliminate.getStaffId());
//		System.out.println(staffId);
//		this.staffService.updState(staffId);
//		return "welcome";
//	}
	
}
